/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.ban.data.exchange.runner.master;

import cn.ac.iie.di.ban.data.exchange.runner.commons.protocol.ScopeEnum;
import cn.ac.iie.di.ban.data.exchange.runner.commons.protocol.TaskTypeEnum;
import cn.ac.iie.di.ban.data.exchange.runner.commons.protocol.task.order.TaskOrderRequest;
import cn.ac.iie.di.ban.data.exchange.runner.commons.protocol.task.order.TaskOrderResponse;
import java.util.HashMap;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import org.apache.log4j.Logger;

/**
 *
 * @author Administrator
 */
public class SlaveTools {

    static Logger logger = Logger.getLogger(SlaveTools.class);

    public static TaskOrderResponse sendToSlave(Function<TaskOrderRequest, CompletableFuture<TaskOrderResponse>> producer, HashMap dataMap) {
        String sql = (String) dataMap.get("sql");
        ScopeEnum scope = (ScopeEnum) dataMap.get("scope");
        String uniq_key = (String) dataMap.get("uniq_key");
        TaskTypeEnum type = (TaskTypeEnum) dataMap.get("type");
        String result_path = (String) dataMap.get("result_path");
        String task_id = (String) dataMap.get("task_id");
        String uid = (String) dataMap.get("uid");

        //send and response
        TaskOrderRequest taskOrder = new TaskOrderRequest(sql, uid, scope, uniq_key, type, result_path, task_id);
        CompletableFuture<TaskOrderResponse> future1 = producer.apply(taskOrder);
        TaskOrderResponse resopnse = future1.join();
        return resopnse;
    }

}
